package com.huluobo.a2307monthdemo2.live

import androidx.lifecycle.MutableLiveData
import com.huluobo.lib_base.bean.GiftBean
import com.huluobo.lib_base.bean.GoodsBean
import com.huluobo.lib_base.bean.Money
import com.huluobo.lib_base.db.DouYinDatabase
import com.huluobo.lib_base.mvvm.BaseViewModel
import com.huluobo.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 *  Created by LC on 2025/10/9.
 */
@HiltViewModel
class LiveViewModel @Inject constructor(private val apiService: ApiService, private val db: DouYinDatabase) :
    BaseViewModel() {
    val followSuccess by lazy { MutableLiveData<String>() }
    fun followAuth(map: Map<String, Any>) {
        executeNetwork(
            { apiService.followAuth(mapToJson(map)) },
            followSuccess::postValue
        )
    }

    val unFollowSuccess by lazy { MutableLiveData<String>() }
    fun unFollowAuth(map: Map<String, Any>) {
        executeNetwork(
            { apiService.unFollowAuth(mapToJson(map)) },
            unFollowSuccess::postValue
        )
    }

    val getGiftSuccess by lazy { MutableLiveData<List<GiftBean>>() }
    fun getGift() {
        executeNetwork(
            { apiService.getGift() },
            getGiftSuccess::postValue
        )
    }

    val queryMoneySuccess by lazy { MutableLiveData<Money>() }
    fun queryMoney(name: String) {
        executeDb(
            { db.getMoneyDao().queryMoneyByName(name) },
            queryMoneySuccess::postValue
        )
    }

    val updateMoneySuccess by lazy { MutableLiveData<String>() }
    fun updateMoney(money: Money) {
        executeDb(
            {
                db.getMoneyDao().updateMoney(money)
                "更新余额成功"
            },
            updateMoneySuccess::postValue
        )
    }

    val getGoodsSuccess by lazy { MutableLiveData<List<GoodsBean>>() }
    fun getGoods(currentPage: Int, pageSize: Int) {
        executeNetwork(
            { apiService.getGoods(currentPage, pageSize) },
            getGoodsSuccess::postValue
        )
    }
}